package com.jm.common.conf.mybatis;

import org.apache.ibatis.type.LocalDateTimeTypeHandler;
import org.springframework.stereotype.Component;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.LocalDateTime;

/**
 * @author kong
 * 实体日期类型 localdatetime兼容
 */
@Component
public class MybatisLocalDateTimeTypeHandler extends LocalDateTimeTypeHandler {

    @Override
    public LocalDateTime getResult(ResultSet rs, String columnName) throws SQLException {
        Object object = rs.getObject(columnName);
        if (object == null) {
            return null;
        }
        if (object instanceof Timestamp) {
            //可以根据自己的需要进行转化
            return ((Timestamp) object).toLocalDateTime();
        }

        return super.getResult(rs, columnName);
    }
}